package com.lanhao.aot.carrierintegration.guotai;

import org.apache.commons.codec.binary.Base64;

import com.aliyun.openservices.shade.com.alibaba.fastjson.JSON;
import com.lanhao.aot.carrierintegration.guotai.dto.LabelRequestDTO;
import com.lanhao.aot.carrierintegration.guotai.util.RSAUtils;

import cn.hutool.core.lang.UUID;
import cn.hutool.http.HttpUtil;

public class GuotaiCallUtil {
	public static String getLabelUrl = "http://47.103.83.25/smt-integration-test/guotai/v1/getLogisticsLabel";
	public static String ahPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgoUJlreOBHzkqfXKPNLo6QuZSPOdZF6Je2WxWs+ktM9bi2T1UrCRPftbCdmE6VOhrkmjV25EkQkoH0WUxfyZ7UHYYLwASgDm+rJSnax0lZX5+HYBikDL7vBn3FxHyVCOUM1XrHUkDLoaKJpabndbBhzRJWESHQcSwsdvdSWo6Z/rLjnsGgi/ciQhhPvHQsfrYL1Zij/+zPZK/cW3FF4WjdsHwVtibSz43lWdbZwdKy75zUX9U43Fkrzbg5uEVV8PvcZzYwVfHhPTqU5gvQyUKkZHL4HsldRmW8GqEGyobWqL36hkqAZqpOmaITY3RnBiCSnO4c2VFh4E4VHiRexYGQIDAQAB";
	public static String ahPrivateKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCChQmWt44EfOSp9co80ujpC5lI851kXol7ZbFaz6S0z1uLZPVSsJE9+1sJ2YTpU6GuSaNXbkSRCSgfRZTF/JntQdhgvABKAOb6slKdrHSVlfn4dgGKQMvu8GfcXEfJUI5QzVesdSQMuhoomlpud1sGHNElYRIdBxLCx291Jajpn+suOewaCL9yJCGE+8dCx+tgvVmKP/7M9kr9xbcUXhaN2wfBW2JtLPjeVZ1tnB0rLvnNRf1TjcWSvNuDm4RVXw+9xnNjBV8eE9OpTmC9DJQqRkcvgeyV1GZbwaoQbKhtaovfqGSoBmqk6ZohNjdGcGIJKc7hzZUWHgThUeJF7FgZAgMBA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GNDlsNlX6x2Jgz8CFMmVXps5jI4t01g3jo7xfNou/3XGIo5YrGqkD8HQPfZO8UWHnMtFoD8xvoPPaPnw+RehN/Z5m/pkW/HOJ6A/cCs+yQRrG3bLNa2Yd70KAGhxOqb4WQ==";

	public static void main(String[] args) {
		try {
			LabelRequestDTO labelRequest = new LabelRequestDTO();
			labelRequest.setTaskNo(UUID.fastUUID().toString().replaceAll("-", ""));
			labelRequest.setShipperArea("");
			labelRequest.setShipperCity("Birmingham");
			labelRequest.setShipperName("Mr. Lee");
			labelRequest.setShipperPhone("+44 (0)121 331 5000");
			labelRequest.setShipperPostcode("B5 5JU");
			labelRequest.setShipperProvince("England");
			labelRequest.setShipperStreet("Birmingham City University University House 15 Bartholomew Row");
			
			labelRequest.setAddresseeArea("");
			labelRequest.setAddresseeCity("London");
			labelRequest.setAddresseeName("UK-RTN-GT");
			labelRequest.setAddresseePhone("07405255344");
			labelRequest.setAddresseePostcode("E1 1RD");
			labelRequest.setAddresseeProvince("England");
			labelRequest.setAddresseeStreet("Alliance station ltd( AliExpress Return service), Suite 126,145-147 Boston Road, Hanwell,");
			labelRequest.setStoreCode("CKUKLD0001");
			labelRequest.setLogisticsCompanyCode("Royal Mail");
			labelRequest.setCountry("UK");
			labelRequest.setLogisticsMode("");
			String reuqestString = JSON.toJSONString(labelRequest);
			System.out.println("请求入参request=" + reuqestString);
			// TODO 这一步缺了base64吗
			
			byte[] encryptByPublicKey = RSAUtils.encryptByPublicKey(reuqestString.getBytes("UTF-8"), ahPublicKey);
			String encryptRequest = Base64.encodeBase64String(encryptByPublicKey);
			System.out.println("使用公钥加密后的request=" + encryptRequest);
			String result = HttpUtil.post(getLabelUrl, encryptRequest);
			System.out.println("收到远程调用结果result=" + result);
			// 先base64 decode
			byte[] decodeBase64 = Base64.decodeBase64(encryptRequest);
			byte[] decryptByPrivateKey = RSAUtils.decryptByPrivateKey(decodeBase64, ahPrivateKey);
			
			System.out.println(new String(decryptByPrivateKey, "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
	}
}
